package com.dasel.math

import groovyx.gpars.ParallelArrayUtil
import static groovyx.gpars.Parallelizer.*


//import static VectorUtils.*
/**
 * Created by IntelliJ IDEA.
 * User: benoit
 * Date: 28-Feb-2010
 * Time: 18:12:22
 * To change this template use File | Settings | File Templates.
 */
@Typed
class Vrid {
    Integer rows
    Integer cols
    List<double[]> matrix
    
    Vrid plus(Vrid right) {
        withParallelizer {
            List<double[]> results = ParallelArrayUtil.collectParallel((0..<rows), {int i ->
                double[] a = this.matrix[i]
                double[] b = right.matrix[i]
                double[] r = new double[cols];
                for (int j = 0; j < cols; j++) {
                    r[j] = a[j] + b[j];
                }
                r
            })

             return new Vrid(matrix: results, rows: rows, cols: cols)
        }
    }

    Vrid plus(Number right) {
        List<double[]> results = new ArrayList<double[]>(rows);
        for (int i = 0; i < rows; i++) {
            double[] a = this.matrix[i]
            double[] r = new double[cols]
            for (int j = 0; j < cols; j++) {
                r[j] = a[j] + right
            }
            results[i] = r
        }
        return new Vrid(matrix: results, rows: rows, cols: cols)

    }

    Vrid multiply(Vrid right) {
        withParallelizer {
            List<double[]> results = ParallelArrayUtil.collectParallel((0..<rows), {int i ->
                double[] a = this.matrix[i]
                double[] b = right.matrix[i]
                double[] r = new double[cols];
                for (int j = 0; j < cols; j++) {
                    r[j] = a[j] * a[j];
                }
                r
            })

             return new Vrid(matrix: results, rows: rows, cols: cols)
        }
    }

    Vrid multiply(Number right) {
        List<double[]> results = new ArrayList<double[]>(rows);
        for (int i = 0; i < rows; i++) {
            double[] a = this.matrix[i]
            double[] r = new double[cols]
            for (int j = 0; j < cols; j++) {
                r[j] = a[j] * right
            }
            results[i] = r
        }
        return new Vrid(matrix: results, rows: rows, cols: cols)

    }


}